﻿using System;
using System.IO;

namespace Mars.Network
{
    public sealed class SendState : IDisposable
    {
        private const int DefaultBufferLength = 1024 * 64;
        private bool m_Disposed;

        public SendState()
        {
            Stream = new MemoryStream(DefaultBufferLength);
            m_Disposed = false;
        }

        public MemoryStream Stream { get; private set; }

        public void Reset()
        {
            Stream.Position = 0L;
            Stream.SetLength(0L);
        }

        public void Dispose()
        {
            Dispose(true);
            GC.SuppressFinalize(this);
        }

        private void Dispose(bool disposing)
        {
            if (m_Disposed)
            {
                return;
            }

            if (disposing)
            {
                if (Stream != null)
                {
                    Stream.Dispose();
                    Stream = null;
                }
            }

            m_Disposed = true;
        }
    }
}